<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/5/31
  Time: 17:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/ucenter/address.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
<section>
    <div class="my_address">
        <form id="form" onsubmit="return false">
            <input type="hidden" value="${userinfo.id}" name="accountId">
            <div class="cont">
                <span>收货人:</span>
                <input id="consignee" type="text" class="txt" name="consignee" placeholder="请输入收货人名称" value="${dizhi.consignee}">
            </div>
            <div class="cont">
                <span>手机号码:</span>
                <input id="phone" type="text" class="txt" name="phone" placeholder="请输入手机号码" value="${dizhi.phone}">
            </div>
            <div class="cont">
                <span>配送楼宇:</span>
                <a id="peis">
                <c:choose>
                    <c:when test="${empty dizhi}">
                        <input type="text"  value="${area.builderName}" class="m_selsct" disabled>
                        <input type="hidden" name="builderId" value="${area.builderid}">
                    </c:when>
                    <c:otherwise>
                        <input type="text"  value="${dizhi.builderName}" class="m_selsct" disabled>
                        <input type="hidden" name="builderId" value="${dizhi.builderId}">
                        <input type="hidden" name="id" value="${dizhi.id}">
                    </c:otherwise>
                </c:choose>
                </a>
            </div>
            <div class="cont">
                <span>公司楼层:</span>
                <input type="text" class="txt" name="floorNo" placeholder="请输入楼层" value="${dizhi.floorNo}">
            </div>
            <div class="cont">
                <span>详细地址:</span>
                <input type="text" class="txt" name="detail" placeholder="请输入地址" value="${dizhi.detail}">
            </div>

            <input type="button" value="保存地址" class="save_btn" onclick="add()">

        </form>


    </div>
</section>
<p>请先选择配送楼宇，以免选择楼宇后页面跳转，之前填写的信息被清空</p>
<script>

    $("#peis").click(function() {
        var name = $("#consignee").val();
        var phone = $("#phone").val();
        var url = '/home/chooseArea.do?cityId=${area.id}&name='+name+'&phone='+phone;
        $("#peis").attr('href',url)

        <%--$("#peis").attr('href','/home/chooseArea.do?cityId=${area.id}&name='+name+'&phone='+phone);--%>
    })


    function add() {
        console.log($("#form").serialize());
//        if ($("input[name='consignee']").val().length == 0){
//            tip("","收货人不能为空",true);
//        }
        $.post("/mobile/user/address?action=${action}",$("#form").serialize(),function (data) {
            if (!data.success){
                tip("",data.msg,true);
            }else {
                window.location.replace("${target}");
            }
        },"json");
    }
</script>
</body>
</html>
